﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace TCC.ControleFluxoDeCaixa.Apresentacao.ResourcesDictionaries.Converters
{
    [ValueConversion(typeof (DateTime), typeof (DateTime))]
    public class DateTimeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DateTime result = DateTime.Parse(((DateTime) value).ToShortDateString());

            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DateTime result;

            if (DateTime.TryParse((string) value, out result) == false)
                return null;

            return result;
        }

    }
}